package com.qyhl.party.party.study.subject;

import com.qyhl.party.common.PartyUrl;
import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.news.NewsBean;
import com.qyhl.webtv.commonlib.entity.news.UnionBean;

import java.util.List;

public class PartySubjectModel implements PartySubjectContract.PartySubjectModel {
    private PartySubjectPresenter mPresenter;

    public PartySubjectModel(PartySubjectPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getSub(String catalogId) {
        EasyHttp.get(PartyUrl.PARTY_SUBJECT_LIST)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("tagName", CommonUtils.getInstance().getSiteName())
                .params("type", "0")
                .params("setions", catalogId)
                .execute(new SimpleCallBack<List<UnionBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.setError("获取失败！");
                    }

                    @Override
                    public void onSuccess(List<UnionBean> unionBeans) {
                        mPresenter.setSub(unionBeans);
                    }
                });
    }

    @Override
    public void getList(String InnerCode, String ID) {
        EasyHttp.get(PartyUrl.PARTY_STUDY_NEWS)
                .params("InnerCode", InnerCode)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("tagName", CommonUtils.getInstance().getSiteName())
                .params("ID", ID)
                .execute(new SimpleCallBack<List<NewsBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        mPresenter.setError("获取内容失败！");
                    }

                    @Override
                    public void onSuccess(List<NewsBean> beanList) {
                        mPresenter.setList(beanList);
                    }
                });
    }
}
